<template> 
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选搜索</span>
                <el-button
                        style="float: right"
                        @click="searchShopPaylistList()"
                        type="primary"
                        size="small">
                    查询结果
                </el-button>
            </div>
            <div style="margin-top: 15px">
                <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
                    <el-form-item label="输入搜索：">
                        <el-input style="width: 203px" v-model="listQuery.keyword" placeholder="类型名称/关键字"></el-input>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <el-card class="operate-container" shadow="never">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
            <!--
                <el-button
                    class="btn-add"
                    @click="addShopPaylist()"
                    size="mini">
                添加
            </el-button>
             -->
        </el-card>
        <div class="table-container">
            <el-table ref="shopPaylistTable"
                      :data="list"
                      style="width: 100%"
                      @selection-change="handleSelectionChange"
                      v-loading="listLoading"
                      border>
                <el-table-column type="selection" width="60" align="center"></el-table-column>



                            <el-table-column prop="skuOutId"
                                             label="出库记录">
                                <template slot-scope="scope">
                                    {{scope.row.skuOutId }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="transactionId" width="250"
                                             label="官方订单号">
                                <template slot-scope="scope">
                                    {{scope.row.transactionId }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="outTradeNo" width="250"
                                             label="平台交易号">
                                <template slot-scope="scope">
                                    {{scope.row.outTradeNo }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="totalFee" width="120"
                                             label="金额">
                                <template slot-scope="scope">
                                    {{scope.row.totalFee }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="msg" width="200"
                                             label="提示消息">
                                <template slot-scope="scope">
                                    {{scope.row.msg }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="storeId" width="120"
                                             label="门店编号">
                                <template slot-scope="scope">
                                    {{scope.row.storeId }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="storeName" width="200"
                                             label="门店名称">
                                <template slot-scope="scope">
                                    {{scope.row.storeName }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="payChannel" width="120"
                                             label="支付方式">
                                <template slot-scope="scope">
                                    {{scope.row.payChannel }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="terminalNumber" width="120"
                                             label="终端号">
                                <template slot-scope="scope">
                                    {{scope.row.terminalNumber }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="time" width="200"
                                             label="时间">
                                <template slot-scope="scope">
                                    {{scope.row.time }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="status" width="120"
                                             label="状态码">
                                <template slot-scope="scope">
                                    {{scope.row.status }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="createName" width="120"
                                             label="创建人">
                                <template slot-scope="scope">
                                    {{scope.row.createName }}
                                </template>
                            </el-table-column>


                            <el-table-column prop="createTime" width="200"
                                             label="创建时间">
                                <template slot-scope="scope">
                                    {{scope.row.createTime |formatCreateTime }}
                                </template>
                            </el-table-column>


              
                    <el-table-column label="操作" width="120" align="center">
                    <template slot-scope="scope">
                         <!--
                        <el-button
                                size="mini"
                                @click="handleUpdate(scope.$index, scope.row)">编辑
                        </el-button>
                        -->
                        <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除
                        </el-button>
                    </template>
                </el-table-column>
                
            </el-table>
        </div>
        <div class="batch-operate-container">

        </div>
        <div class="pagination-container">
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    layout="total, sizes,prev, pager, next,jumper"
                    :page-size="listQuery.pageSize"
                    :page-sizes="[5,10,15]"
                    :current-page.sync="listQuery.pageNum"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
    //将$都替换为$
    import {fetchList, deleteShopPaylist} from '@/api/mer/shopPaylist'
    import {formatDate} from '@/utils/date';

    export default {
        name: 'shopPaylistList',
        data() {
            return {
                operates: [],
                operateType: null,
                listQuery: {
                    keyword: null,
                    pageNum: 1,
                    pageSize: 10
                },
                list: null,
                total: null,
                listLoading: true,
                multipleSelection: []
            }
        },
        created() {
            this.getList();
        },
        filters: {
            formatCreateTime(time) {
                let date = new Date(time);
                return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
            },

            formatStatus(value) {
                if (value === 1) {
                    return '未开始';
                } else if (value === 2) {
                    return '活动中';
                } else if (value === 3) {
                    return '已结束';
                } else if (value === 4) {
                    return '已失效';
                }
            },
        },
        methods: {
            getList() {
                this.listLoading = true;
                fetchList(this.listQuery).then(response => {
                    this.listLoading = false;
                this.list = response.data.records;
                this.total = response.data.total;
                this.totalPage = response.data.pages;
                this.pageSize = response.data.size;
            })
                ;

            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleUpdate(index, row) {
                this.$router.push(
                    {path: '/sales/updateShopPaylist', query: {id: row.id}})
            },
            handleDelete(index, row) {
                this.$confirm('是否要删除该类型', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    deleteShopPaylist(row.id
            ).
                then(response => {
                    this.$message({
                        message: '删除成功',
                        type: 'success',
                        duration: 1000
                    });
                this.getList();
            })
                ;

            })
                ;

            },


            handleSizeChange(val) {
                this.listQuery.pageNum = 1;
                this.listQuery.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.listQuery.pageNum = val;
                this.getList();
            },
            searchShopPaylistList() {
                this.listQuery.pageNum = 1;
                this.getList();
            },
            handleBatchOperate() {
                console.log(this.multipleSelection);
                if (this.multipleSelection < 1) {
                    this.$message({
                        message: '请选择一条记录',
                        type: 'warning',
                        duration: 1000
                    });
                    return;
                }
                let showStatus = 0;
                if (this.operateType === 'showShopPaylist') {
                    showStatus = 1;
                } else if (this.operateType === 'hideShopPaylist') {
                    showStatus = 0;
                } else {
                    this.$message({
                        message: '请选择批量操作类型',
                        type: 'warning',
                        duration: 1000
                    });
                    return;
                }
                let ids = [];
                for (let i = 0; i < this.multipleSelection.length; i++) {
                    ids.push(this.multipleSelection[i].id);
                }
                let data = new URLSearchParams();
                data.append("ids", ids);
                data.append("showStatus", showStatus);
                updateShowStatus(data).then(response => {
                    this.getList();
                this.$message({
                    message: '修改成功',
                    type: 'success',
                    duration: 1000
                });
            })
                ;
            },
            addShopPaylist() {
                //手动将router,改成$router
                this.$router.push({path: '/sales/addShopPaylist'})
            }
        }
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>


</style>


